import {
  PostRes,
  DisableRes,
  RefTonOrderMedia,
  putTonOrderMediaDto,
  TonOrderMediaGateway,
  deleteTonOrderMediaDto,
  TonOrderMediaInterfaceWithGrant,
} from "qqlx-core";

import { ViewBase, ViewBaseAction } from "../view-base";
import { RefTonOrderMediaSchema } from "@/river/ton-order";

export class ViewTonOrderMedia extends ViewBase<RefTonOrderMedia> implements ViewBaseAction<RefTonOrderMedia>, TonOrderMediaInterfaceWithGrant<{}> {
  private static instance: ViewTonOrderMedia;
  static getInstance(options?: { isSingleton?: boolean }) {
    if (options?.isSingleton === false) {
      return new ViewTonOrderMedia();
    }

    if (!this.instance) this.instance = new ViewTonOrderMedia();
    return this.instance;
  }

  getSchema(): RefTonOrderMedia {
    return new RefTonOrderMediaSchema();
  }

  private constructor() {
    super();
    this.initial();
    this.insertDefaultCondition();
  }

  async put(dto: putTonOrderMediaDto) {
    this.pending();
    return this.$request.put<putTonOrderMediaDto, PostRes<RefTonOrderMedia>>(TonOrderMediaGateway.path, dto);
  }

  async delete(dto: deleteTonOrderMediaDto) {
    this.pending();
    return this.$request.delete<deleteTonOrderMediaDto, DisableRes>(TonOrderMediaGateway.path, dto);
  }
}
